package cn.hsa.fqz.task.controller;

import cn.hsa.fqz.task.service.TUserMappingService;
import cn.hsa.fqz.task.service.dto.UserMappingMinDTO;
import cn.hsa.hsaf.core.framework.context.HsafContextHolder;
import cn.hsa.hsaf.core.framework.util.CurrentUser;
import cn.hsa.hsaf.core.framework.web.WrapperResponse;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description TODO
 * @ClassName LoginController
 * @Author Liu.Jun
 * @Create 2023-04-22 15:14
 * @Version 1.0.0
 */
@RequestMapping("/fqz")
@RestController
@Slf4j
@Api(tags = {"获取用户信息"})
public class HealthController {

    @Value("${zmjk.monitor.mock}")
    private boolean isMock;

    @Autowired
    private TUserMappingService userMappingService;

    @GetMapping("/auth/user")
    public WrapperResponse<CurrentUser> createReport(){
        CurrentUser currentUser = HsafContextHolder.getContext().getCurrentUser();
        if(isMock){
            currentUser.setAdmDvs("430000");
        }
        log.info("当前用户信息: "+ JSON.toJSONString(currentUser));
        if(currentUser == null){
            return WrapperResponse.error(404, "未找到登录用户",null);
        }
        return WrapperResponse.success(currentUser);
    }

    @Autowired
    private RedisTemplate<String,String> template;

    @GetMapping("/echo")
    public WrapperResponse<String> echo(){
        String result = "success";
        template.opsForValue().set("keys",result);
        String res = template.opsForValue().get("keys");
        return WrapperResponse.success(res);
    }

    @ApiOperation(value = "查询所有用户信息", notes = "查询所有用户信息")
    @GetMapping("/user/list")
    public WrapperResponse<List<UserMappingMinDTO>> getUserListByName(){
        List<UserMappingMinDTO> ls = userMappingService.getAllUserMapping();
        return WrapperResponse.success(ls);
    }
}
